/*
 * GenericJPADAOFactory.java
 *
 * Created on 3 de Julho de 2007, 10:28
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.unifor.finance.business.persistence;

import br.unifor.finance.common.business.entity.TipoDespesa;
import br.unifor.finance.common.dto.PersistentObject;
import br.unifor.finance.persistence.dao.GenericDAO;
import br.unifor.finance.persistence.dao.jpa.GenericJPADAO;
import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Clebernaice, Cleilson, Leonardo
 */
public class GenericJPADAOFactory extends DAOAbstractFactory {
  
  private GenericJPADAO<TipoDespesa, Integer> tipoDespesaDAO;
  
  private EntityManagerFactory emf;
  private EntityManager emg;
  
  /** Creates a new instance of GenericJPADAOFactory */
  GenericJPADAOFactory() {
    this("finance-business-PUTest");
  }
  
  GenericJPADAOFactory(String persistenceUnit) {
    emf = Persistence.createEntityManagerFactory(persistenceUnit);
    emg = emf.createEntityManager();
  }
  
  GenericJPADAOFactory(EntityManager emg) {
    this.emg = emg;
  }

  public synchronized <E extends PersistentObject, K extends Serializable> GenericDAO<E, K> getGenericDAO() {
    return null;
  }

  public synchronized GenericDAO<TipoDespesa, Integer> getTipoDespesaDAO() {
    if (tipoDespesaDAO == null)
      tipoDespesaDAO = new GenericJPADAO<TipoDespesa, Integer>(emg);
    return tipoDespesaDAO;
  }
     
}
